package leesoft.hub.actions;

import java.util.Map;
import java.util.logging.Logger;
import leesoft.toolbox.PropertyManager;
import java.util.HashMap;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import org.apache.commons.dbutils.handlers.MapHandler;
import org.apache.commons.dbutils.handlers.ScalarHandler;
import java.sql.ResultSet;
import org.apache.commons.dbutils.ResultSetHandler;
import org.apache.commons.dbutils.DbUtils;

import java.sql.*;
import java.util.List;
import java.util.Map; 

import leesoft.data.databeans.ApplicationInfoItem;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ApplicationInfoAction implements IAction,ResultSetHandler<ApplicationInfoItem> {

	public Map process(SessionContext ctx) {
		// TODO Auto-generated method stub
		String aid=ctx.getParameterString("aid");
		String diverName=PropertyManager.getInstance().getValue("datasource.driverClassName");
		String connectionString=PropertyManager.getInstance().getValue("datasource.url");
		String username=PropertyManager.getInstance().getValue("datasource.username");
		String password=PropertyManager.getInstance().getValue("datasource.password");
		
		Connection conn;
		
		try{
			Class.forName(diverName);
			conn=DriverManager.getConnection(connectionString,username,password);
			QueryRunner run = new QueryRunner();
			ApplicationInfoItem appInfo=run.query(conn,"select * from tap_application where aid=?",this,aid);
			HashMap returnMap=new HashMap();
			returnMap.put("applicationInfo", appInfo);
			DbUtils.close(conn);  
			return returnMap;
		}catch(Exception e){
			e.printStackTrace();
			return null;
		}finally{
			
		}
	}
	public ApplicationInfoItem handle(ResultSet rs) throws SQLException {
		ApplicationInfoItem  appInfo=new ApplicationInfoItem();
        if(rs.next()){
        	appInfo.setAid(rs.getString("aid"));
        	appInfo.setName(rs.getString("name"));
        	appInfo.setBirth(rs.getString("birth"));
        	appInfo.setContact(rs.getString("contact"));
        	appInfo.setIdnum(rs.getString("idnum"));
        	appInfo.setAddress(rs.getString("address"));
        	appInfo.setCreateDt(rs.getString("create_dt"));
        	appInfo.setResult(rs.getString("result"));
        }
        return appInfo;
    }
	public void setRequest(HttpServletRequest request){}
	public void setResponse(HttpServletResponse response){}

}
